package org.wj.problem

import org.wj.problem.InorderTraversal.TreeNode

import scala.collection.mutable

object RecoverTree {

  def main(args: Array[String]): Unit = {
    val root = new TreeNode(1)
    val left = new TreeNode(2)
    val right = new TreeNode(3)
    root.right = right
    root.left = left
    recoverTree(root)
  }

  def recoverTree(root: TreeNode): Unit = {
    var varRoot = root
    val stack = new mutable.ArrayStack[TreeNode]()
    var list = List[Int]()
    while (stack.nonEmpty || varRoot != null){
      if(varRoot!=null){
        list = list :+ varRoot.value
        stack.push(varRoot)
        varRoot = varRoot.left
      }else{
        val node = stack.pop()
        varRoot = node.right
      }
    }
    
  }
}
